package site.marqstree.latte.ui.banner;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import com.bigkoo.convenientbanner.holder.Holder;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;

import site.marqstree.latte.core.app.Latte;
import site.marqstree.latte.ui.R;

/*
 * 项目名: EleCommerce
 * 包名: site.marqstree.latte.ui.banner
 * 文件名: BannerHolder
 * 创建者: marqstree
 * 创建时间: 2020/1/26 18:44
 * 描述: TODO
 */
public class BannerHolder extends Holder<String> {
    //轮播图View布局中只有一个ImageView控件
    private ImageView mImageView;

    //默认构造函数
    public BannerHolder(View itemView) {
        super(itemView);
    }

    //获取轮播图布局中的控件
    @Override
    protected void initView(View itemView) {
        mImageView =itemView.findViewById(R.id.ivBanner);
    }

    private static final RequestOptions BANNER_OPTIONS = new RequestOptions()
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .dontAnimate()
            .centerCrop();

    //更新轮播图
    //data:本地图片资源ID
    @Override
    public void updateUI(String url) {
        //设置图片
        Glide.with(Latte.getApplicationContext())
                .load(url)
                .apply(BANNER_OPTIONS)
                .into(mImageView);
    }
}

